package com.wfm.niuke.doublepoint;

import java.util.HashMap;

public class PThree无重复字符的最长子串 {
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public int lengthOfLongestSubstring(String s) {
        int i= 0;
        int max = 0;
        HashMap<Character,Integer> m = new HashMap<>();
        for (int j = 0; j < s.length(); j++) {
            char c = s.charAt(j);
            // 后面的条件考虑了abba的问题
            if(m.containsKey(c)&&i<m.get(c)+1){
                i=m.get(c)+1;
            }
            m.put(s.charAt(j),j);
            max= Math.max(j-i+1,max);
        }
        return max;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new PThree无重复字符的最长子串().new Solution();
    }
}